package com.yixun.qfbao.hander;

import com.yixun.qfbao.model.enums.SystemIdEnum;
import com.yixun.qfbao.util.WxAccessTokenCacheUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yixun.qfbao.api.service.PremisesApiService;
import com.yixun.qfbao.apidto.ChangePremisesSaleStatusReqDto;
import com.yixun.qfbao.apidto.ChangePremisesSaleStatusResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.vo.ChangePremisesSaleStatusReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;

/**
 * （14）	楼盘交易状态变更 
 * 
 * @author jzliu
 *		
 */
@Service("changePremisesSaleStatusHander")
public class ChangePremisesSaleStatusHander extends CommonAbstractHander {
	private static Logger logger= LoggerFactory.getLogger(ChangePremisesSaleStatusHander.class);
	
	@Autowired
	private PremisesApiService premisesService;
	@Autowired
	private WxAccessTokenCacheUtils wxAccessTokenCacheUtils;
	
	@SuppressWarnings("rawtypes")
	@Override
	public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
		ChangePremisesSaleStatusReqVo req = (ChangePremisesSaleStatusReqVo)reqDto;
		ChangePremisesSaleStatusReqDto reqDto1 = req.getParams();
		BaseResponseDTO<ChangePremisesSaleStatusResDto> res = new BaseResponseDTO<ChangePremisesSaleStatusResDto>();
		ChangePremisesSaleStatusResDto resDto = new ChangePremisesSaleStatusResDto();
		try {
			//获取分销助手和案场助手的微信accessToken
			String agencyAccessToken = wxAccessTokenCacheUtils.getAccessToken(reqDto1.getCompanyUuid(), SystemIdEnum.AGENCY_h5.getCode(), reqDto1.getDomain());
			String assistantAccessToken = wxAccessTokenCacheUtils.getAccessToken(reqDto1.getCompanyUuid(), SystemIdEnum.ASSISTANT.getCode(), reqDto1.getDomain());
			reqDto1.setAgencyToken(agencyAccessToken);
			reqDto1.setAssistantToken(assistantAccessToken);
			resDto = premisesService.changePremisesSaleStatus(reqDto1);
		} catch (Exception e) {
			logger.error("ChangePremisesSaleStatusHander error: {}", e);
			resDto.setResult(ResultEnum.FAIL.getNo());
			resDto.setResultMsg("楼盘审核失败!");
		}
		res.setResData(resDto);
		res.setResult(resDto.getResult());
		return res;
	}
	
}
